package com.dididoctor.doctor.Activity.Usercentre.MyPurse.InComeList;

import android.content.Context;

import com.dididoctor.doctor.Activity.ConstantValue;
import com.dididoctor.doctor.Bean.Token;
import com.dididoctor.doctor.Http.MyHttpResponseHandler;
import com.dididoctor.doctor.MV.BasePresenter;
import com.dididoctor.doctor.MV.BusinessClient;
import com.dididoctor.doctor.MV.Response;
import com.dididoctor.doctor.Utils.Util;
import com.loopj.android.http.RequestParams;

import org.apache.http.Header;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @version 2.0
 * @类描述： 登陆页
 * @项目名称：ddgh
 * @类名称： loginActivity
 * @包名称： com.doudoukeji.service.Activity.login
 * @创建人：张强 boy
 * @创建时间：2016/3/7 16:40
 * @修改人：
 * @修改时间：2016/3/7 16:40
 * @修改备注： new parent class(用一句话描述修改了什么)
 */
public class ComeInPresenter extends BasePresenter {
    private ComeInView view;

    public ComeInPresenter(Context context, ComeInView view) {
        super(context, view);
        this.view = view;
    }

    public void lunch(int pageIndex) {
//        userId	String	是	用户
//        token	String	是
//        pageIndex	String	否	页码，第一页从开始
//        pageSize	String	否	页容量
        RequestParams params = new RequestParams();
        params.put("userId", Token.getUserId());
        params.put("token", Token.getToken());
        params.put("pageSize", "10");
        params.put("pageIndex", pageIndex);
        BusinessClient.post(ConstantValue.walletincome, params, new MyHttpResponseHandler(view) {
            private List<Map<String, Object>> maps = new ArrayList<Map<String, Object>>();
            private List<ComeInBean> orderBeans = new ArrayList<ComeInBean>();
            private String cometype = "";

            @Override
            public void onMyResponse(Response response) {
                if (response.isSucceed()) {
                    maps = response.getObjectListData("income");
                    for (Map<String, Object> map : maps) {
                        ComeInBean comeInBean = new ComeInBean();
                        comeInBean.setClientName(Util.toString(map.get("clientName")));
                        cometype = Util.toString(map.get("type"));
                        if ("1".equals(cometype)) {
                            comeInBean.setType("图文咨询");
                        } else if ("2".equals(cometype)) {
                            comeInBean.setType("电话咨询");
                        } else {
                            comeInBean.setType("签约服务");
                        }
                        comeInBean.setMoney((Double) map.get("money") + "");
                        comeInBean.setPayDate(Util.toString(map.get("payDate")));
                        orderBeans.add(comeInBean);
                    }
                    view.getincomesucced(orderBeans);
                } else {
                    view.showToastMessage(response.getMsg());
                }
            }

            @Override
            public void onFailure(int i, Header[] headers, byte[] bytes, Throwable throwable) {
                super.onFailure(i, headers, bytes, throwable);
                view.getincomefail();
            }
        });
    }
}
